package dome2;

public class Computer {
    public void open() {
        System.out.println("开机！");
    }

    public void close() {
        System.out.println("关机！");
    }

    public void useDevice(IUSB iusb) {
        iusb.openDevice();
        if(iusb instanceof Mouse) {//判断Mouse这个类有没有实现这个IUSB这个接口
            Mouse mouse = (Mouse) iusb; //这里是向下转型
            mouse.click();//调用Mouse这个类特有的方法
        }else if(iusb instanceof KeyBoard) {
            KeyBoard keyBoard = (KeyBoard) iusb;
            keyBoard.inPut();
        }
        iusb.closeDevice();
    }
}
